Euler Problem 205

Peter has nine four-sided (pyramidal) dice, each with faces numbered 1, 2, 3, 4. Colin has six six-sided (cubic) dice, each with faces numbered 1, 2, 3, 4, 5, 6.

Peter and Colin roll their dice and compare totals: the highest total wins. The result is a draw if the totals are equal.

What is the probability that Pyramidal Pete beats Cubic Colin? Give your answer rounded to seven decimal places in the form 0.abcdefg


In [1]:
from collections import defaultdict

peter = defaultdict(float)
colin = defaultdict(float)
peter[0] = 1.0
colin[0] = 1.0

for _ in range(9):
    for n in range(36, -1, -1):
        peter[n] = sum(peter[n-k] for k in [1,2,3,4])/4

for _ in range(6):
    for n in range(36, -1, -1):
        colin[n] = sum(colin[n-k] for k in [1,2,3,4,5,6])/6

print ("%.7f" % sum(peter[i]*colin[j] for i in range(37) for j in range(i)))


0.5731441

In [ ]: